package web;

import service.Register;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class RegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String identity=req.getParameter("identity");
        System.out.println(identity+"register");
        String name=req.getParameter("user");
        String pwd=req.getParameter("pwd");
        boolean result=false;
        if(identity.equals("student")){
            result=Register.addStudent(name,pwd);
        }else if(identity.equals("teacher")){
            result=Register.addTeacher(name,pwd);
        }//这里之前要加上验证，规定必须选择身份。
        if(result){
//            resp.sendRedirect("login.jsp");
            resp.getWriter().write("true");
        }else{
            resp.getWriter().write("false");
        }
    }
}
